package com.example.framework2002a.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.BindingAdapter;
import androidx.databinding.DataBindingUtil;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.framework2002a.R;
import com.example.framework2002a.databinding.ItemNewlistBinding;
import com.example.framework2002a.databinding.ItemNewtypeBinding;
import com.example.lib_core.bean.NewsListBean;

import java.util.List;

public class NewListAdapter extends BaseQuickAdapter<NewsListBean, BaseViewHolder> {

    public NewListAdapter(@Nullable List<NewsListBean> data) {
        super(R.layout.item_newlist, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, NewsListBean newsListBean) {
        ItemNewlistBinding binding = DataBindingUtil.getBinding(baseViewHolder.itemView);
        if (binding != null){
            binding.setNewlist(newsListBean);
            binding.executePendingBindings();
        }
    }

    @Override
    protected void onItemViewHolderCreated(@NonNull BaseViewHolder viewHolder, int viewType) {
        super.onItemViewHolderCreated(viewHolder, viewType);
        DataBindingUtil.bind(viewHolder.itemView);
    }

    @BindingAdapter(value = "image")
    public static void getImage(ImageView imageView, String url){
        Glide.with(imageView.getContext()).load(url).into(imageView);
    }
}
